package com.mall.biz.mall;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.mallGroupBuy.MallGroupbBuyService;
import com.mall.pojo.MallGroupBuy;
import com.mall.pojo.MallGroupBuyExample;
import com.mall.pojo.MallGroupBuyExample.Criteria;
import com.mall.query.MallGroupBuyQuery;

@Service
public class MallGroupBuyBizImpl {
	@Autowired
	private MallGroupbBuyService mallGroupbBuyService;
	
	public List<MallGroupBuy> getMallGroupBuyListByQuery(MallGroupBuyQuery mallGroupBuyQuery){
		
		
		MallGroupBuyExample mallGroupBuyExample = new MallGroupBuyExample();
		
		mallGroupBuyExample.setLimit(mallGroupBuyQuery.getPage().getLength());
		mallGroupBuyExample.setStart(mallGroupBuyQuery.getPage().getBegin());
		mallGroupBuyExample.setOrderByClause("id desc");
		Criteria criteria = mallGroupBuyExample.createCriteria();
		criteria.andCommOnlyKeyEqualTo(mallGroupBuyQuery.getOnlyKey());
		if (StringUtils.isNotBlank(mallGroupBuyQuery.getKeyWord())) {
			criteria.andPyNameLike("%" + mallGroupBuyQuery.getKeyWord() + "%");
		}
		if (mallGroupBuyQuery.getCategoryId() != null && mallGroupBuyQuery.getCategoryId() > 0) {
			criteria.andCategoryIdEqualTo(mallGroupBuyQuery.getCategoryId());
		}
		if (mallGroupBuyQuery.getSecCategoryId() != null && mallGroupBuyQuery.getSecCategoryId() > 0) {
			criteria.andSecCategoryIdEqualTo(mallGroupBuyQuery.getSecCategoryId());
		}
		criteria.andStatusEqualTo(0);// 取上线的团购商品
		List<MallGroupBuy> mallGroupBuyList = mallGroupbBuyService.getMallGroupBuyListByExample(mallGroupBuyExample);
		return mallGroupBuyList;
		
	}

}
